class Solution {
public:
    int longestSubsequence(vector<int>& arr, int difference)
    {
        int n = arr.size();
        int ret = 1;
        unordered_map<int, int> mp;
        mp[arr[0]] = 1;
        for (int i = 1; i < n; i++)
        {
            mp[arr[i]] = mp[arr[i] - difference] + 1;
            ret = max(ret, mp[arr[i]]);

        }


        return ret;

    }
};